﻿using System.Xml;

namespace SignalRDemo.Common.Helpers
{
    /// <summary>
    /// XML文件操作帮助类
    /// </summary>
    public static class XMLHelper
    {
        /// <summary>
        /// 获取XML文件
        /// </summary>
        /// <param name="strFilePath">物理存储路径</param>
        /// <returns></returns>
        public static XmlDocument GetXmlDocument(string strFilePath) {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(strFilePath); //加载XML文档
            return xmlDoc;
        }
        /// <summary>
        /// 获取单个节点
        /// </summary>
        /// <param name="xmlDoc">XmlDocument文件</param>
        /// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名")</param>
        /// <returns></returns>
        public static XmlNode GetXmlNodeByXpath(XmlDocument xmlDoc, string xpath)
        {       
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            return xmlNode;          
        }

        /// <summary>
        /// 获取多个节点名称
        /// </summary>
        /// <param name="xmlDoc">XmlDocument文件</param>
        /// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名")</param>
        /// <returns></returns>
        public static XmlNodeList GetXmlNodeListByXpath(XmlDocument xmlDoc, string xpath)
        {
            XmlNodeList xmlNodeList = xmlDoc.SelectNodes(xpath);
            return xmlNodeList;
        }

    }
}